<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>编辑简历</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.7.2/font/bootstrap-icons.css">
</head>
<body>
    <div th:replace="common/header :: header"></div>

    <div class="container mt-4">
        <div class="card">
            <div class="card-header">
                <h5 class="mb-0">编辑简历</h5>
            </div>
            <div class="card-body">
                <form id="resumeForm" onsubmit="return submitForm(event)">
                    <input type="hidden" name="id" th:value="${resume.id}">
                    
                    <div class="row mb-3">
                        <div class="col-md-6">
                            <label class="form-label">应聘职位 <span class="text-danger">*</span></label>
                            <select class="form-select" name="jobId" required>
                                <option value="">选择职位</option>
                                <option th:each="job : ${jobs}" 
                                        th:value="${job.id}" 
                                        th:text="${job.title}"
                                        th:selected="${job.id == resume.jobId}">
                                </option>
                            </select>
                        </div>
                        <div class="col-md-6">
                            <label class="form-label">学历 <span class="text-danger">*</span></label>
                            <select class="form-select" name="education" required>
                                <option value="">选择学历</option>
                                <option value="大专" th:selected="${resume.education == '大专'}">大专</option>
                                <option value="本科" th:selected="${resume.education == '本科'}">本科</option>
                                <option value="硕士" th:selected="${resume.education == '硕士'}">硕士</option>
                                <option value="博士" th:selected="${resume.education == '博士'}">博士</option>
                            </select>
                        </div>
                    </div>

                    <div class="row mb-3">
                        <div class="col-md-6">
                            <label class="form-label">学校 <span class="text-danger">*</span></label>
                            <input type="text" class="form-control" name="school" th:value="${resume.school}" required>
                        </div>
                        <div class="col-md-6">
                            <label class="form-label">专业 <span class="text-danger">*</span></label>
                            <input type="text" class="form-control" name="major" th:value="${resume.major}" required>
                        </div>
                    </div>

                    <div class="mb-3">
                        <label class="form-label">工作经验 <span class="text-danger">*</span></label>
                        <textarea class="form-control" name="workExperience" rows="4" required th:text="${resume.workExperience}"></textarea>
                    </div>

                    <div class="mb-3">
                        <label class="form-label">技能特长 <span class="text-danger">*</span></label>
                        <textarea class="form-control" name="skills" rows="4" required th:text="${resume.skills}"></textarea>
                    </div>

                    <div class="mb-3">
                        <label class="form-label">状态</label>
                        <div class="form-check">
                            <input class="form-check-input" type="radio" name="status" value="PENDING" th:checked="${resume.status == 'PENDING'}">
                            <label class="form-check-label">待处理</label>
                        </div>
                        <div class="form-check">
                            <input class="form-check-input" type="radio" name="status" value="REVIEWING" th:checked="${resume.status == 'REVIEWING'}">
                            <label class="form-check-label">审核中</label>
                        </div>
                        <div class="form-check">
                            <input class="form-check-input" type="radio" name="status" value="APPROVED" th:checked="${resume.status == 'APPROVED'}">
                            <label class="form-check-label">已通过</label>
                        </div>
                        <div class="form-check">
                            <input class="form-check-input" type="radio" name="status" value="REJECTED" th:checked="${resume.status == 'REJECTED'}">
                            <label class="form-check-label">已拒绝</label>
                        </div>
                    </div>

                    <div class="text-center">
                        <button type="submit" class="btn btn-primary">
                            <i class="bi bi-save"></i> 保存
                        </button>
                        <button type="button" class="btn btn-secondary" onclick="history.back()">
                            <i class="bi bi-x"></i> 取消
                        </button>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
    <script>
        function submitForm(event) {
            event.preventDefault();
            
            const form = document.getElementById('resumeForm');
            const formData = new FormData(form);
            const data = Object.fromEntries(formData.entries());

            axios.post('/resume/update', data)
                .then(response => {
                    alert('保存成功');
                    location.href = '/resume/list';
                })
                .catch(error => {
                    alert('保存失败：' + (error.response?.data?.message || '未知错误'));
                });

            return false;
        }
    </script>
</body>
</html> 